<template>
  <!-- <el-container class="layout-container-demo" style="height: 500px">
    <el-header style="text-align: right; font-size: 12px">
      <div class="toolbar">
        <el-dropdown>
          <el-icon style="margin-right: 8px; margin-top: 1px"
            ><setting
          /></el-icon>
          <template #dropdown>
            <el-dropdown-menu>
              <el-dropdown-item>View</el-dropdown-item>
              <el-dropdown-item>Add</el-dropdown-item>
              <el-dropdown-item>Delete</el-dropdown-item>
            </el-dropdown-menu>
          </template>
        </el-dropdown>
        <span>Tom</span>
      </div>
    </el-header>
    <el-container>
      <el-aside style="background-color: white" width="200px" height="100%">
        <el-scrollbar>
          <el-menu>
            <el-sub-menu index="1">
              <template #title> 系统管理 </template>
              <el-menu-item index="1-1" @click="goToRoute('userList')"
                >用户管理</el-menu-item
              >
              <el-menu-item index="1-2" @click="goToRoute('repayScheme')"
                >角色管理</el-menu-item
              >
            </el-sub-menu>
            <el-sub-menu index="2">
              <template #title> 审批管理 </template>
              <el-menu-item index="2-1">审批列表</el-menu-item>
            </el-sub-menu>
          </el-menu>
        </el-scrollbar>
      </el-aside>
      <el-divider direction="vertical" style="height: 100%" />
      <el-main style="margin-left: 20px; height: 550px">
        <router-view />
      </el-main>
    </el-container>
  </el-container> -->

  <div id="app" class="layout">
    <router-view />
  </div>
</template>

<script lang="ts" setup>
import { onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
import { useI18n } from 'vue-i18n'

const router = useRouter()
const { locale } = useI18n()

onMounted(() => {
  console.log('App mounted')
  // 获取哈希值（包括 '?' 之后的查询字符串）
  const hash = window.location.hash
// 提取 '?' 之后的查询字符串部分
  const queryString = hash.substring(hash.indexOf('?') + 1)
// 使用 URLSearchParams 来解析查询字符串
  const urlParams = new URLSearchParams(queryString)
  // const urlParams = new URLSearchParams(window.location.search)
  console.log('urlParams:', urlParams)
  const lang = urlParams.get('lang')
  if (lang && ['zh', 'id'].includes(lang)) {
    locale.value = lang
  }
})

const goToRoute = (routeName: string) => {
  router.push({ name: routeName })
}
</script>

<style scoped>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
  height: 100vh;
}

.layout {
  background: #f5f7f9;
  position: relative;
  overflow: hidden;
  height: 100%;
}

.layout-container-demo .el-header {
  position: relative;
  background-color: var(--el-color-primary-light-7);
  color: var(--el-text-color-primary);
}

.layout-container-demo .el-aside {
  color: var(--el-text-color-primary);
  background: var(--el-color-primary-light-8);
}

.layout-container-demo .el-menu {
  border-right: none;
}

.layout-container-demo .el-main {
  padding: 0;
}

.layout-container-demo .toolbar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  right: 20px;
}
</style>
